package com.tgy.programmer_code_interview_guide._02_linkedList;

/**
 * @Author: tgy
 * @Date: 1/22/21 2:18 PM
 */
public class Nodes {

    public static void printNode(Node node) {

        StringBuilder sb = new StringBuilder();
        while (node != null) {

            sb.append(node.val);
            sb.append(',');
            node = node.next;
        }

        System.out.println(sb.toString());
    }

    public static Node generalNode(int[] nums,boolean circle) {

        if (nums == null || nums.length == 0) {

            return null;
        }

        Node dummyNode = new Node();
        Node tailNode = dummyNode;

        for (int num : nums) {
            //
            tailNode.next = new Node(num);
            tailNode = tailNode.next;
        }

        if (circle) {

            tailNode.next = dummyNode.next;
        }

        return dummyNode.next;

    }

}
